package setvice;
import Dao.DecreateDao;
import entity.Decreate;
import Dao.DecreateDaoimpl;
import entity.User;
import setvice.DecreateService;
import java.util.List;
public class DecreateServiceimpl implements DecreateService{
    DecreateDao decreateDao=new DecreateDaoimpl();
    /*
    添加装扮操作
     */
    @Override
    public boolean insertDecreateService(Decreate decreate) {
        decreateDao.insertDecreate(decreate);
        System.out.println("添加成功!");
        return true;
    }
    /*
    删除装扮操作
     */
    public boolean deleteDecreateByDecreateThemeController(Integer id, String theme){
        List<Decreate> decreateList=decreateDao.seekDecreateById(id);
        if(decreateList!=null){
            decreateDao.deleteDecreateByDecreateTheme(id,theme);
            System.out.println("删除成功!");
            return true;
        }
        else{
            System.out.println("该装扮不存在,删除失败!");
            return false;
        }
    }
    /*
    更改装扮信息
     */
    public boolean changeDecreateByIdService(Integer id,String theme,Decreate decreate){
        List<Decreate> decreateList=decreateDao.seekDecreateById(id);
        if(decreateList!=null){
            for(int i=0;i<decreateList.size();i++){
                Decreate decreate1=decreateList.get(i);
                if(decreate1.getTheme().equals(theme)){
                    decreateDao.changeDecreateById(id,theme,decreate);
                    System.out.println("更改成功!");
                }
            }
            return true;
        }
        else{
            System.out.println("装扮不存在,更改失败!");
            return false;
        }
    }

    @Override
    public List<Decreate> seekAllDecreateService() {
        List<Decreate> decreateList=decreateDao.seekAllDecreate();
        if(decreateList!=null){
            return decreateList;
        }
        else{
            System.out.println("没有该用户装扮!");
            return null;
        }
    }
    /*
    根据用户id，查询装扮
     */
    @Override
    public List<Decreate> seekDecreateByIdService(Integer id) {
        List<Decreate> decreateList=decreateDao.seekDecreateById(id);
        if(decreateList!=null){
            return decreateList;
        }
        else{
            System.out.println("此装扮不存在");
            return null;
        }
    }
}
